package com.qingyouchuxing.mall.biz.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qingyouchuxing.mall.biz.domain.dto.MallMailAddressDTO;
import com.qingyouchuxing.mall.biz.domain.vo.MallMailAddressVO;
import com.qingyouchuxing.mall.biz.service.IMallMailAddressService;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.web.annotation.RepeatSubmit;
import com.ruoyi.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品寄件地址管理
 *
 * @author 数据小王子
 * 2024-11-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mail/address")
public class MallMailAddressController extends BaseController {
    @Autowired
    private IMallMailAddressService iMallMailAddressService;
    /**
     * 添加商品寄货地址
     *
     * @param dto
     * @return
     */
    @SaCheckPermission("mall:mail:add")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public R<Void> add(@RequestBody @Validated MallMailAddressDTO dto) {
        return toR(iMallMailAddressService.addMailAddress(dto));
    }

    /**
     * 删除商品寄货地址
     *
     * @param id 寄货地址id
     */
    @SaCheckPermission("mall:mail:remove")
    @Log(title = "商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    public R<Void> del(Long fkTenantId, Long id) {
        return toR(iMallMailAddressService.removeMailAddressById(fkTenantId,id));
    }

    /**
     * 修改商品寄货地址
     *
     * @param dto
     * @return
     */
    @SaCheckPermission("mall:mail:edit")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public R<?> update(@RequestBody @Validated MallMailAddressDTO dto) {
        return toR(iMallMailAddressService.updateMailAddress(dto));
    }




    /**
     * 查询商品寄货地址
     *
     * @param id
     * @return
     */
    @GetMapping
    public R<List<MallMailAddressVO>> getMailAddressById(Long fkTenantId,Long id) {
        List<MallMailAddressVO> mallMailAddressVOS
            = iMallMailAddressService.selectMailAddressByIdList(fkTenantId, id);
        return R.ok(mallMailAddressVOS);
    }
}
